﻿using System;

namespace PrimeFactors
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Prime Factors Finder!");

            // 输入一个数字
            Console.Write("Enter a number: ");
            int number;
            while (!int.TryParse(Console.ReadLine(), out number) || number <= 0)
            {
                Console.WriteLine("Invalid input. Please enter a positive integer:");
            }

            // 输出所有素数因子
            Console.Write($"Prime factors of {number}: ");
            for (int i = 2; i <= number; i++)
            {
                if (number % i == 0 && IsPrime(i))
                {
                    Console.Write($"{i} ");
                }
            }
            Console.WriteLine();
        }

        // 检查一个数是否为素数
        static bool IsPrime(int num)
        {
            if (num < 2) return false;
            for (int i = 2; i * i <= num; i++)
            {
                if (num % i == 0) return false;
            }
            return true;
        }
    }
}
